package com.xmy.cultivate.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmy.cultivate.entity.*;
import com.xmy.cultivate.entity.response.ArrivalRate;
import com.xmy.cultivate.entity.response.PassRade;
import com.xmy.cultivate.entity.response.PassRadeDetail;
import com.xmy.cultivate.entity.views.ChaPlan;
import com.xmy.cultivate.entity.views.LeadDataRs;
import com.xmy.cultivate.entity.views.RenewClassRecord;
import com.xmy.cultivate.entity.views.StudyPlan;
import com.xmy.cultivate.feign.IPlanFeignClient;
import com.xmy.cultivate.feign.IPlanHolidayFeignClient;
import com.xmy.cultivate.feign.math_outside.IMathematicsFeignClient;
import com.xmy.cultivate.mapper.*;
import com.xmy.cultivate.respons.EduTask;
import com.xmy.cultivate.respons.PlanShutNum;
import com.xmy.cultivate.service.*;
import com.xmy.cultivate.util.CommonUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class StudyPlanImpl implements IStudyPlanService {

    @Autowired
    @Lazy
    RenewClassMapper renewClassMapper;

    @Autowired
    @Lazy
    TrackMapper trackMapper;

    @Autowired
    @Lazy
    TrackDetailMapper trackDetailMapper;

    @Autowired
    @Lazy
    IQuarterService iQuarterService;

    @Autowired
    @Lazy
    GradeMapper gradeMapper;

    @Autowired
    @Lazy
    StudentGradeMapper studentGradeMapper;

    @Autowired
    @Lazy
    IGradeService iGradeService;

    @Autowired
    @Lazy
    IPlanFeignClient iPlanFeignClient;

    @Autowired
    @Lazy
    IStudentService iStudentService;

    @Autowired
    @Lazy
    ICourseTypeService iCourseTypeService;

    @Autowired
    @Lazy
    IStudentGradeService iStudentGradeService;

    @Autowired
    @Lazy
    IMathematicsFeignClient iMathematicsFeignClient;

    @Autowired
    IOrganizationService iOrganizationService;

    @Autowired
    RoleAdminMapper roleAdminMapper;

    @Autowired
    @Lazy
    IPlanHolidayFeignClient iPlanHolidayFeignClient;

    @Autowired
    ISchoolQuarterService iSchoolQuarterService;

    /**
     * 获取通过
     *
     * @param schoolId
     * @param yearPart
     * @param yearClassId
     * @param type
     * @param classTypeId
     * @param subjectsId
     * @param quarterNum
     * @param startDate
     * @param endDate
     * @param trackId
     * @param gradeSection
     * @return
     */
    public List<StudyPlan> getPlanList(String schoolId, String yearPart, String yearClassId, Integer type, String classTypeId, String subjectsId, String quarterNum, String startDate, String endDate, String trackId, String gradeSection, String lessonType) {

        Quarter quarter = iQuarterService.getNowQuarter();
        if (StringUtils.isNotBlank(yearPart) && StringUtils.isNotBlank(quarterNum)) {
            quarter.setYearPart(Integer.parseInt(yearPart));
            quarter.setNum(Integer.parseInt(quarterNum));
        }

        QueryWrapper queryWrapper = new QueryWrapper();

        queryWrapper.eq(StringUtils.isNotBlank(subjectsId), "subjects_id", subjectsId);
        queryWrapper.eq("year_part", quarter.getYearPart());
        queryWrapper.eq("quarter_num", quarter.getNum());
        queryWrapper.eq("deleted", 0);

        if (StringUtils.isNotBlank(yearClassId)) {
            queryWrapper.eq("year_class_id", yearClassId);
        }
        if (StringUtils.isNotBlank(gradeSection)) {
            if (gradeSection.equals("0")) {
                queryWrapper.in("year_class_id", 0, 1, 2);
            } else if (gradeSection.equals("1")) {
                queryWrapper.in("year_class_id", 3, 4, 5, 6);
            } else if (gradeSection.equals("2")) {
                queryWrapper.in("year_class_id", 7, 8, 9);
            } else if (gradeSection.equals("3")) {
                queryWrapper.in("year_class_id", 10, 11, 12);
            }
        }


        List<StudyPlan> studyPlanList = new ArrayList<>();
        List<RenewClassRecord> renewClassRecordList = null;

        List<String> groupBys = new ArrayList<>();
        //1老师，2校区老师，3校长，4校区
        if (type.equals(1)) {
            groupBys.add("teacher_id");
            if (StringUtils.isNotBlank(trackId)) {
                //queryWrapper.inSql("teacher_id","select sourse_id from track_detail where deleted = 0 and track_id ="+trackId);
            }
        } else if (type.equals(2)) {
            groupBys.add("school_id");
            groupBys.add("teacher_id");
        } else if (type.equals(3)) {
            queryWrapper.inSql("teacher_id", "select admin_id from role_admin where role_id = 1568160887369994242 ");
            groupBys.add("teacher_id");

        } else if (type.equals(4)) {
            groupBys.add("school_id");
            if (StringUtils.isNotBlank(trackId)) {
                //queryWrapper.inSql("school_id","select sourse_id from track_detail where deleted = 0 and track_id ="+trackId);
            }
        }
        groupBys.add("quarter_num");
        if (StringUtils.isNotBlank(subjectsId)) {
            groupBys.add("subjects_id");
        }

        queryWrapper.groupBy(groupBys);

        if (type.equals(1)) {
            renewClassRecordList = renewClassMapper.getRenewRecordPerson(queryWrapper);
        } else if (type.equals(2)) {
            queryWrapper.eq(StringUtils.isNotBlank(schoolId), "school_id", schoolId);
            renewClassRecordList = renewClassMapper.getRenewRecord(queryWrapper);
        } else if (type.equals(3)) {
            renewClassRecordList = renewClassMapper.getRenewRecordPerson(queryWrapper);
        } else if (type.equals(4)) {
            renewClassRecordList = renewClassMapper.getRenewRecordSchool(queryWrapper);
        }

        //List<Long> teacherSubjects  = new ArrayList<>();

        for (RenewClassRecord renewClassRecord : renewClassRecordList) {

            StudyPlan studyPlan = new StudyPlan();
            BeanUtils.copyProperties(renewClassRecord, studyPlan);
            studyPlan.setSchoolId(renewClassRecord.getSchoolId());
            studyPlan.setTeacherId(renewClassRecord.getTeacherId());

            QueryWrapper<StudentGrade> studentGradeQueryWrapper = new QueryWrapper<>();
            studentGradeQueryWrapper.eq("subjects_id", subjectsId);
            //teacherSubjects = gradeMapper.getTeacherGradeSubjects(quarter.getYearPart(),quarter.getNum(),renewClassRecord.getTeacherId());

            //1老师，2校区老师，3校长，4校区
            if (type.equals(1)) {
                studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + renewClassRecord.getTeacherId() + "");
            } else if (type.equals(2)) {
                studentGradeQueryWrapper.eq("school_id", renewClassRecord.getSchoolId());
                studentGradeQueryWrapper.inSql("grade_id", "select id from grade where school_id = " + renewClassRecord.getSchoolId() + " and teacher_id = " + renewClassRecord.getTeacherId() + "");
            } else if (type.equals(3)) {
                studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + renewClassRecord.getTeacherId() + "");
            } else if (type.equals(4)) {
                studentGradeQueryWrapper.eq("school_id", renewClassRecord.getSchoolId());
            }

            studentGradeQueryWrapper.eq(StringUtils.isNotBlank(subjectsId), "subjects_id", subjectsId);
            studentGradeQueryWrapper.eq("year_part", quarter.getYearPart());
            studentGradeQueryWrapper.eq("quarter_num", quarter.getNum());
            studentGradeQueryWrapper.notIn("status", 3, 4);//订单作废的不算,转校转出的不算
            studentGradeQueryWrapper.eq("deleted", 0);
            studentGradeQueryWrapper.eq("is_last", 1);
            studentGradeQueryWrapper.ne("is_makeup", 1);//是否补课（跨学期补课，统计率要排除掉）
            if (StringUtils.isNotBlank(yearClassId)) {
                studentGradeQueryWrapper.eq("year_class_id", yearClassId);
            }
            if (StringUtils.isNotBlank(gradeSection)) {
                if (gradeSection.equals("0")) {
                    studentGradeQueryWrapper.in("year_class_id", 0, 1, 2);
                } else if (gradeSection.equals("1")) {
                    studentGradeQueryWrapper.in("year_class_id", 3, 4, 5, 6);
                } else if (gradeSection.equals("2")) {
                    studentGradeQueryWrapper.in("year_class_id", 7, 8, 9);
                } else if (gradeSection.equals("3")) {
                    studentGradeQueryWrapper.in("year_class_id", 10, 11, 12);
                }
            }
            studentGradeQueryWrapper.eq("lesson_type", lessonType);

            QueryWrapper<StudentGrade> studentGradeQueryWrapper2 = studentGradeQueryWrapper.clone();
            studentGradeQueryWrapper2.groupBy("student_id");

            List<Long> studentIdList = studentGradeMapper.getGroupByAtNewStudentIdList(studentGradeQueryWrapper2);
            //System.out.println("studentCount:" + studentIdList.size());

            //studentGradeQueryWrapper.in("status",1);

            //获取带班总人数
            Integer studentAllCount = renewClassMapper.getStudentAllCount(studentGradeQueryWrapper);
            studyPlan.setAllStudentCount(studentAllCount);

            PlanShutNum planShutNum = new PlanShutNum();
            planShutNum.setYearPart(Integer.parseInt(yearPart));
            planShutNum.setQuarterNum(Integer.parseInt(quarterNum));
            if (StringUtils.isNotBlank(classTypeId)) {
                planShutNum.setClassTypeId(classTypeId);
            }
            if (StringUtils.isNotBlank(yearClassId)) {
                planShutNum.setYearClassId(yearClassId);
            }
            planShutNum.setStudentIdList(studentIdList);
            if (StringUtils.isNotBlank(gradeSection)) {
                planShutNum.setGradeSection(Integer.parseInt(gradeSection));
            }

            try {
                Map<String, Object> rsMap = iPlanFeignClient.getPlanShutNum(planShutNum);
                Integer alreadyShutNum = (Integer) rsMap.get("planShutNum");//已通关关数
                Integer allShutNum = (Integer) rsMap.get("shutNumAll");//总关数
                Integer planShutNumPass = (Integer) rsMap.get("planShutNumPass");//学习进度，已通关关数（不大于课程里设置的应通关关数）
                Integer shutNumShouldPassAll = (Integer) rsMap.get("shutNumShouldPassAll");

                studyPlan.setAlreadyShutNum(alreadyShutNum);
                studyPlan.setAllShutNum(allShutNum);
                studyPlan.setPlanShutNumPass(planShutNumPass);
                studyPlan.setShutNumShouldPassAll(shutNumShouldPassAll);

                studyPlan.setNotShutNum(allShutNum - alreadyShutNum);
            } catch (Exception e) {
                //System.out.println("连接异常");
                //System.out.println(e.getMessage());
            }
            studyPlanList.add(studyPlan);
        }
        return studyPlanList;
    }

    public IPage<StudyPlan> getPlanDetail(String schoolId, String teacherId, String gradeId, String yearPart, String yearClassId, Integer type, String classTypeId, String subjectsId, String quarterNum, String startDate, String endDate, String trackId, String gradeSection, String lessonType, Integer pageNum, Integer pageSize) {


        IPage<StudyPlan> iPage = new Page<>(pageNum, pageSize);

        Quarter quarter = iQuarterService.getNowQuarter();
        if (StringUtils.isNotBlank(yearPart) && StringUtils.isNotBlank(quarterNum)) {
            quarter.setYearPart(Integer.parseInt(yearPart));
            quarter.setNum(Integer.parseInt(quarterNum));
        }


        //StudyPlan studyPlan = new StudyPlan();

        QueryWrapper<StudentGrade> studentGradeQueryWrapper = new QueryWrapper<>();
        studentGradeQueryWrapper.eq("subjects_id", subjectsId);
        //teacherSubjects = gradeMapper.getTeacherGradeSubjects(quarter.getYearPart(),quarter.getNum(),renewClassRecord.getTeacherId());
        if (StringUtils.isNotBlank(gradeId)) {
            studentGradeQueryWrapper.eq("grade_id", gradeId);
        }
        //1老师，2校区老师，3校长，4校区
        if (type.equals(1)) {
            studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + teacherId + "");
        } else if (type.equals(2)) {
            studentGradeQueryWrapper.eq("school_id", schoolId);
            studentGradeQueryWrapper.inSql("grade_id", "select id from grade where school_id = " + schoolId + " and teacher_id = " + teacherId + "");

        } else if (type.equals(3)) {
            studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + teacherId + "");
        } else if (type.equals(4)) {
            studentGradeQueryWrapper.eq("school_id", schoolId);
        }

        studentGradeQueryWrapper.eq(StringUtils.isNotBlank(subjectsId), "subjects_id", subjectsId);
        studentGradeQueryWrapper.eq("year_part", quarter.getYearPart());
        studentGradeQueryWrapper.eq("quarter_num", quarter.getNum());
        studentGradeQueryWrapper.notIn("status", 3, 4);//订单作废的不算,转校转出的不算
        studentGradeQueryWrapper.eq("deleted", 0);
        studentGradeQueryWrapper.eq("is_last", 1);
        studentGradeQueryWrapper.ne("is_makeup", 1);
        if (StringUtils.isNotBlank(yearClassId)) {
            studentGradeQueryWrapper.eq("year_class_id", yearClassId);
        }
        if (StringUtils.isNotBlank(gradeSection)) {
            if (gradeSection.equals("0")) {
                studentGradeQueryWrapper.in("year_class_id", 0, 1, 2);
            } else if (gradeSection.equals("1")) {
                studentGradeQueryWrapper.in("year_class_id", 3, 4, 5, 6);
            } else if (gradeSection.equals("2")) {
                studentGradeQueryWrapper.in("year_class_id", 7, 8, 9);
            } else if (gradeSection.equals("3")) {
                studentGradeQueryWrapper.in("year_class_id", 10, 11, 12);
            }
        }
        studentGradeQueryWrapper.eq("lesson_type", lessonType);

        QueryWrapper<StudentGrade> studentGradeQueryWrapper2 = studentGradeQueryWrapper.clone();
        studentGradeQueryWrapper2.groupBy("student_id");

        studentGradeMapper.getGroupByAtNewStudentList(iPage, studentGradeQueryWrapper2);

        //List<StudyPlan> studyPlanList = iPage.getRecords();

        for (StudyPlan studyPlan : iPage.getRecords()) {
            //获取带班总人数
            //Integer studentAllCount = renewClassMapper.getStudentAllCount(studentGradeQueryWrapper);
            //studyPlan.setAllStudentCount(studentAllCount);
            Student student = iStudentService.getById(studyPlan.getStudentId());
            if (student == null)
                continue;
            Grade grade = iGradeService.getById(studyPlan.getGradeId());
            if (grade != null) {
                studyPlan.setYearClassName(CommonUtil.getYearClassNameForId(grade.getYearClassId().getKey()));
                CourseType courseType = iCourseTypeService.getById(grade.getCourseTypeId());
                studyPlan.setClassTypeName(courseType.getName());
            }

            studyPlan.setStudentName(student.getName());

            PlanShutNum planShutNum = new PlanShutNum();
            planShutNum.setYearPart(Integer.parseInt(yearPart));
            planShutNum.setQuarterNum(Integer.parseInt(quarterNum));
            if (StringUtils.isNotBlank(classTypeId)) {
                planShutNum.setClassTypeId(classTypeId);
            }
            if (StringUtils.isNotBlank(yearClassId)) {
                planShutNum.setYearClassId(yearClassId);
            }

            Long studentId = studyPlan.getStudentId();
            List<Long> stuList = new ArrayList<Long>();
            stuList.add(studentId);
            planShutNum.setStudentIdList(stuList);
            if (StringUtils.isNotBlank(gradeSection))
                planShutNum.setGradeSection(Integer.parseInt(gradeSection));
            try {
                Map<String, Object> rsMap = iPlanFeignClient.getPlanShutNum(planShutNum);
                Integer planShutNumAlready = (Integer) rsMap.get("planShutNum");
                Integer shutNumAll = (Integer) rsMap.get("shutNumAll");
                Integer planShutNumPass = (Integer) rsMap.get("planShutNumPass");//学习进度，已通关关数（不大于课程里设置的应通关关数）
                Integer shutNumShouldPassAll = (Integer) rsMap.get("shutNumShouldPassAll");

                studyPlan.setAlreadyShutNum(planShutNumAlready);
                studyPlan.setAllShutNum(shutNumAll);
                studyPlan.setPlanShutNumPass(planShutNumPass);
                studyPlan.setShutNumShouldPassAll(shutNumShouldPassAll);
                studyPlan.setNotShutNum(shutNumAll - planShutNumAlready);
            } catch (Exception e) {
                //System.out.println("连接异常");
                //System.out.println(e.getMessage());
            }
            //studyPlanList.add(studyPlan);
        }

        return iPage;
    }


    public List<StudyPlan> getGoUpList(String schoolId, String yearPart, String yearClassId, Integer type, String classTypeId, String subjectsId, String quarterNum, String startDate, String endDate, String trackId, String gradeSection) {

        Quarter quarter = iQuarterService.getNowQuarter();
        if (StringUtils.isNotBlank(yearPart) && StringUtils.isNotBlank(quarterNum)) {
            quarter.setYearPart(Integer.parseInt(yearPart));
            quarter.setNum(Integer.parseInt(quarterNum));
        }

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("lesson_type", 1);
        queryWrapper.eq(StringUtils.isNotBlank(subjectsId), "subjects_id", subjectsId);
        queryWrapper.eq("year_part", quarter.getYearPart());
        queryWrapper.eq("quarter_num", quarter.getNum());
        queryWrapper.eq("deleted", 0);

        if (StringUtils.isNotBlank(yearClassId)) {
            queryWrapper.eq("year_class_id", yearClassId);
        }
        if (StringUtils.isNotBlank(gradeSection)) {
            if (gradeSection.equals("0")) {
                queryWrapper.in("year_class_id", 0, 1, 2);
            } else if (gradeSection.equals("1")) {
                queryWrapper.in("year_class_id", 3, 4, 5, 6);
            } else if (gradeSection.equals("2")) {
                queryWrapper.in("year_class_id", 7, 8, 9);
            } else if (gradeSection.equals("3")) {
                queryWrapper.in("year_class_id", 10, 11, 12);
            }
        }


        List<StudyPlan> studyPlanList = new ArrayList<>();
        List<RenewClassRecord> renewClassRecordList = null;

        List<String> groupBys = new ArrayList<>();
        //1老师，2校区老师，3校长，4校区
        if (type.equals(1)) {
            groupBys.add("teacher_id");
            if (StringUtils.isNotBlank(trackId)) {
                //queryWrapper.inSql("teacher_id","select sourse_id from track_detail where deleted = 0 and track_id ="+trackId);
            }
        } else if (type.equals(2)) {
            queryWrapper.inSql(StringUtils.isNotBlank(schoolId), "school_id", schoolId);
            groupBys.add("school_id");
            groupBys.add("teacher_id");
        } else if (type.equals(3)) {
            queryWrapper.inSql("teacher_id", "select admin_id from role_admin where role_id = 1568160887369994242 ");
            groupBys.add("teacher_id");

        } else if (type.equals(4)) {
            groupBys.add("school_id");
            if (StringUtils.isNotBlank(trackId)) {
                //queryWrapper.inSql("school_id","select sourse_id from track_detail where deleted = 0 and track_id ="+trackId);
            }
        }
        groupBys.add("quarter_num");
        if (StringUtils.isNotBlank(subjectsId)) {
            groupBys.add("subjects_id");
        }

        queryWrapper.groupBy(groupBys);

        if (type.equals(1)) {
            renewClassRecordList = renewClassMapper.getRenewRecordPerson(queryWrapper);
        } else if (type.equals(2)) {
            renewClassRecordList = renewClassMapper.getRenewRecord(queryWrapper);
        } else if (type.equals(3)) {
            renewClassRecordList = renewClassMapper.getRenewRecordPerson(queryWrapper);
        } else if (type.equals(4)) {
            renewClassRecordList = renewClassMapper.getRenewRecordSchool(queryWrapper);
        }

        //List<Long> teacherSubjects  = new ArrayList<>();

        for (RenewClassRecord renewClassRecord : renewClassRecordList) {

            StudyPlan studyPlan = new StudyPlan();
            BeanUtils.copyProperties(renewClassRecord, studyPlan);
            studyPlan.setSchoolId(renewClassRecord.getSchoolId());
            studyPlan.setTeacherId(renewClassRecord.getTeacherId());

            QueryWrapper<StudentGrade> studentGradeQueryWrapper = new QueryWrapper<>();
            studentGradeQueryWrapper.eq("subjects_id", subjectsId);
            studentGradeQueryWrapper.eq("lesson_type", 1);
            //teacherSubjects = gradeMapper.getTeacherGradeSubjects(quarter.getYearPart(),quarter.getNum(),renewClassRecord.getTeacherId());

            //1老师，2校区老师，3校长，4校区
            if (type.equals(1)) {
                studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + renewClassRecord.getTeacherId() + "");
            } else if (type.equals(2)) {
                studentGradeQueryWrapper.eq("school_id", renewClassRecord.getSchoolId());
                studentGradeQueryWrapper.inSql("grade_id", "select id from grade where school_id = " + renewClassRecord.getSchoolId() + " and teacher_id = " + renewClassRecord.getTeacherId() + "");
            } else if (type.equals(3)) {
                studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + renewClassRecord.getTeacherId() + "");
            } else if (type.equals(4)) {
                studentGradeQueryWrapper.eq("school_id", renewClassRecord.getSchoolId());
            }

            studentGradeQueryWrapper.eq(StringUtils.isNotBlank(subjectsId), "subjects_id", subjectsId);
            studentGradeQueryWrapper.eq("year_part", quarter.getYearPart());
            studentGradeQueryWrapper.eq("quarter_num", quarter.getNum());
            studentGradeQueryWrapper.notIn("status", 3, 4);//订单作废的不算,转校转出的不算
            studentGradeQueryWrapper.eq("deleted", 0);
            studentGradeQueryWrapper.eq("is_last", 1);
            studentGradeQueryWrapper.ne("is_makeup", 1);
            if (StringUtils.isNotBlank(yearClassId)) {
                studentGradeQueryWrapper.eq("year_class_id", yearClassId);
            }
            if (StringUtils.isNotBlank(gradeSection)) {
                if (gradeSection.equals("0")) {
                    studentGradeQueryWrapper.in("year_class_id", 0, 1, 2);
                } else if (gradeSection.equals("1")) {
                    studentGradeQueryWrapper.in("year_class_id", 3, 4, 5, 6);
                } else if (gradeSection.equals("2")) {
                    studentGradeQueryWrapper.in("year_class_id", 7, 8, 9);
                } else if (gradeSection.equals("3")) {
                    studentGradeQueryWrapper.in("year_class_id", 10, 11, 12);
                }
            }

            QueryWrapper<StudentGrade> studentGradeQueryWrapper2 = studentGradeQueryWrapper.clone();
            studentGradeQueryWrapper2.groupBy("student_id");

            List<Long> studentIdList = studentGradeMapper.getGroupByAtNewStudentIdList(studentGradeQueryWrapper2);
            //System.out.println("studentCount:"+studentIdList.size());

            //studentGradeQueryWrapper.in("status",1);

            //获取带班总人数
            Integer studentAllCount = renewClassMapper.getStudentAllCount(studentGradeQueryWrapper);
            studyPlan.setAllStudentCount(studentAllCount);

            PlanShutNum planShutNum = new PlanShutNum();
            planShutNum.setYearPart(Integer.parseInt(yearPart));
            planShutNum.setQuarterNum(Integer.parseInt(quarterNum));
            if (StringUtils.isNotBlank(classTypeId)) {
                planShutNum.setClassTypeId(classTypeId);
            }
            if (StringUtils.isNotBlank(yearClassId)) {
                planShutNum.setYearClassId(yearClassId);
            }
            planShutNum.setStudentIdList(studentIdList);
            if (StringUtils.isNotBlank(gradeSection)) {
                planShutNum.setGradeSection(Integer.parseInt(gradeSection));
            }

            try {
                Map<String, Object> rsMap = iPlanFeignClient.getGoUpData(planShutNum);

                Integer goUpStudentCount = (Integer) rsMap.get("goUpStudentCount");
                studyPlan.setGoUpStudentCount(goUpStudentCount);
            } catch (Exception e) {
                //System.out.println("连接异常");
                //System.out.println(e.getMessage());
            }
            studyPlanList.add(studyPlan);
        }
        return studyPlanList;
    }

    public List<StudyPlan> getGoUpDetail(String schoolId, String teacherId, String gradeId, String yearPart, String yearClassId, Integer type, String classTypeId, String subjectsId, String quarterNum, String startDate, String endDate, String trackId, String gradeSection, String isGoUp, Integer pageNum, Integer pageSize) {


        IPage<StudyPlan> iPage = new Page<>(pageNum, pageSize);

        Quarter quarter = iQuarterService.getNowQuarter();
        if (StringUtils.isNotBlank(yearPart) && StringUtils.isNotBlank(quarterNum)) {
            quarter.setYearPart(Integer.parseInt(yearPart));
            quarter.setNum(Integer.parseInt(quarterNum));
        }


        //StudyPlan studyPlan = new StudyPlan();

        QueryWrapper<StudentGrade> studentGradeQueryWrapper = new QueryWrapper<>();
        studentGradeQueryWrapper.eq("subjects_id", subjectsId);
        //teacherSubjects = gradeMapper.getTeacherGradeSubjects(quarter.getYearPart(),quarter.getNum(),renewClassRecord.getTeacherId());
        if (StringUtils.isNotBlank(gradeId)) {
            studentGradeQueryWrapper.eq("grade_id", gradeId);
        }
        //1老师，2校区老师，3校长，4校区
        if (type.equals(1)) {
            studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + teacherId + "");
        } else if (type.equals(2)) {
            studentGradeQueryWrapper.eq("school_id", schoolId);
            studentGradeQueryWrapper.inSql("grade_id", "select id from grade where school_id = " + schoolId + " and teacher_id = " + teacherId + "");

        } else if (type.equals(3)) {
            studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + teacherId + "");
        } else if (type.equals(4)) {
            studentGradeQueryWrapper.eq("school_id", schoolId);
        }

        studentGradeQueryWrapper.eq(StringUtils.isNotBlank(subjectsId), "subjects_id", subjectsId);
        studentGradeQueryWrapper.eq("year_part", quarter.getYearPart());
        studentGradeQueryWrapper.eq("quarter_num", quarter.getNum());
        studentGradeQueryWrapper.notIn("status", 3, 4);//订单作废的不算,转校转出的不算
        studentGradeQueryWrapper.eq("deleted", 0);
        studentGradeQueryWrapper.eq("is_last", 1);
        studentGradeQueryWrapper.ne("is_makeup", 1);
        if (StringUtils.isNotBlank(yearClassId)) {
            studentGradeQueryWrapper.eq("year_class_id", yearClassId);
        }
        if (StringUtils.isNotBlank(gradeSection)) {
            if (gradeSection.equals("0")) {
                studentGradeQueryWrapper.in("year_class_id", 0, 1, 2);
            } else if (gradeSection.equals("1")) {
                studentGradeQueryWrapper.in("year_class_id", 3, 4, 5, 6);
            } else if (gradeSection.equals("2")) {
                studentGradeQueryWrapper.in("year_class_id", 7, 8, 9);
            } else if (gradeSection.equals("3")) {
                studentGradeQueryWrapper.in("year_class_id", 10, 11, 12);
            }
        }

        QueryWrapper<StudentGrade> studentGradeQueryWrapper2 = studentGradeQueryWrapper.clone();
        studentGradeQueryWrapper2.groupBy("student_id");
        studentGradeQueryWrapper2.eq("lesson_type", 1);
        studentGradeMapper.getGroupByAtNewStudentList(iPage, studentGradeQueryWrapper2);

        List<StudyPlan> studyPlanList = new ArrayList<>();
        StringBuilder stringBuilder = new StringBuilder();
        for (StudyPlan studyPlan : iPage.getRecords()) {
            //获取带班总人数
            //Integer studentAllCount = renewClassMapper.getStudentAllCount(studentGradeQueryWrapper);
            //studyPlan.setAllStudentCount(studentAllCount);
            Student student = iStudentService.getById(studyPlan.getStudentId());
            if (student == null)
                continue;
            Grade grade = iGradeService.getById(studyPlan.getGradeId());
            if (grade != null) {
                studyPlan.setYearClassName(CommonUtil.getYearClassNameForId(grade.getYearClassId().getKey()));
                CourseType courseType = iCourseTypeService.getById(grade.getCourseTypeId());
                studyPlan.setClassTypeName(courseType.getName());
            }

            studyPlan.setStudentName(student.getName());

            PlanShutNum planShutNum = new PlanShutNum();
            planShutNum.setYearPart(Integer.parseInt(yearPart));
            planShutNum.setQuarterNum(Integer.parseInt(quarterNum));
            if (StringUtils.isNotBlank(classTypeId)) {
                planShutNum.setClassTypeId(classTypeId);
            }
            if (StringUtils.isNotBlank(yearClassId)) {
                planShutNum.setYearClassId(yearClassId);
            }

            Long studentId = studyPlan.getStudentId();
            List<Long> stuList = new ArrayList<Long>();
            stuList.add(studentId);
            planShutNum.setStudentIdList(stuList);
            if (StringUtils.isNotBlank(gradeSection))
                planShutNum.setGradeSection(Integer.parseInt(gradeSection));
            try {
                if (studyPlan.getStudentId().equals(1626225665361575936L)) {
                    //System.out.println();
                }
                Map<String, Object> rsMap = iPlanFeignClient.getPlanShutNum(planShutNum);
                Integer planShutNumAlready = (Integer) rsMap.get("planShutNum");//已通关数
                Integer shutNumAll = (Integer) rsMap.get("shutNumAll");//总关数
                studyPlan.setAlreadyShutNum(planShutNumAlready);
                studyPlan.setAllShutNum(shutNumAll);
                studyPlan.setNotShutNum(shutNumAll - planShutNumAlready);

                if (isGoUp.equals("1")) {
                    if (studyPlan.getNotShutNum() <= 0 && shutNumAll > 0) {
                        studyPlanList.add(studyPlan);
                        stringBuilder.append(studyPlan.getStudentId()).append(",");
                    }
                } else if (isGoUp.equals("2")) {
                    if (studyPlan.getNotShutNum() > 0 && shutNumAll > 0)
                        studyPlanList.add(studyPlan);
                } else {
                    studyPlanList.add(studyPlan);
                }


            } catch (Exception e) {
                //System.out.println("连接异常");
                //System.out.println(e.getMessage());
            }
        }
        return studyPlanList;
    }

    @Override
    public List<StudyPlan> getMinimumTaskProgressRate(String schoolId, String yearPart, String yearClassId, Integer type, String classTypeId, String subjectsId, String quarterNum, String startDate, String endDate, String trackId, String gradeSection, Integer passersStatus, Integer taskCourseNum, Integer taskCourseNumNow, Integer taskState, String courseTypeId, String taskDateStart, String taskDateEnd) {
        Quarter quarter = iQuarterService.getNowQuarter();
        if (StringUtils.isNotBlank(yearPart) && StringUtils.isNotBlank(quarterNum)) {
            quarter.setYearPart(Integer.parseInt(yearPart));
            quarter.setNum(Integer.parseInt(quarterNum));
        }

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(StringUtils.isNotBlank(subjectsId), "subjects_id", subjectsId);
        queryWrapper.eq("lesson_type", 1);
        queryWrapper.eq("year_part", quarter.getYearPart());
        queryWrapper.eq("quarter_num", quarter.getNum());
        queryWrapper.eq("deleted", 0);

        if (StringUtils.isNotBlank(yearClassId)) {
            List<String> yearClassList = Arrays.asList(yearClassId.split(","));
            queryWrapper.in("year_class_id", yearClassList);
        }
        if (StringUtils.isNotBlank(gradeSection)) {
            if (gradeSection.equals("0")) {
                queryWrapper.in("year_class_id", 1, 2);//0, 先不包含0的
            } else if (gradeSection.equals("1")) {
                queryWrapper.in("year_class_id", 3, 4, 5, 6);
            } else if (gradeSection.equals("2")) {
                queryWrapper.in("year_class_id", 7, 8, 9);
            } else if (gradeSection.equals("3")) {
                queryWrapper.in("year_class_id", 10, 11, 12);
            }
        } else {
            queryWrapper.ne("year_class_id", 0);// 先不包含0的
        }

        List<StudyPlan> studyPlanList = new ArrayList<>();
        List<RenewClassRecord> renewClassRecordList = null;

        List<String> groupBys = new ArrayList<>();
        //1老师，2校区老师，3校长，4校区
        if (type.equals(1)) {
            groupBys.add("teacher_id");
            if (StringUtils.isNotBlank(trackId)) {
                queryWrapper.inSql("teacher_id", "select sourse_id from track_detail where deleted = 0 and track_id =" + trackId);
            }
        } else if (type.equals(2)) {
            queryWrapper.inSql(StringUtils.isNotBlank(schoolId), "school_id", schoolId);
            groupBys.add("school_id");
            groupBys.add("teacher_id");
        } else if (type.equals(3)) {
            queryWrapper.inSql("teacher_id", "select admin_id from role_admin where role_id = 1568160887369994242 ");
            groupBys.add("teacher_id");

        } else if (type.equals(4)) {
            groupBys.add("school_id");
            if (StringUtils.isNotBlank(trackId)) {
                queryWrapper.inSql("school_id", "select sourse_id from track_detail where deleted = 0 and track_id =" + trackId);
            }
        }
        groupBys.add("quarter_num");
        if (StringUtils.isNotBlank(subjectsId)) {
            groupBys.add("subjects_id");
        }

        queryWrapper.groupBy(groupBys);

        if (type.equals(1) || type.equals(3)) {
            renewClassRecordList = renewClassMapper.getRenewRecordPerson(queryWrapper);
        } else if (type.equals(2)) {
            renewClassRecordList = renewClassMapper.getRenewRecord(queryWrapper);
        } else if (type.equals(4)) {
            renewClassRecordList = renewClassMapper.getRenewRecordSchool(queryWrapper);
        }

        JSONArray objects = new JSONArray();
        for (RenewClassRecord renewClassRecord : renewClassRecordList) {
            StudyPlan studyPlan = new StudyPlan();
            BeanUtils.copyProperties(renewClassRecord, studyPlan);
            studyPlan.setSchoolId(renewClassRecord.getSchoolId());
            studyPlan.setTeacherId(renewClassRecord.getTeacherId());

            QueryWrapper<StudentGrade> studentGradeQueryWrapper = new QueryWrapper<>();
            studentGradeQueryWrapper.eq("lesson_type", 1);
            studentGradeQueryWrapper.eq("subjects_id", subjectsId);

            //1老师，2校区老师，3校长，4校区
            if (type.equals(1)) {
                studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + renewClassRecord.getTeacherId() + "");
            } else if (type.equals(2)) {
                studentGradeQueryWrapper.eq("school_id", renewClassRecord.getSchoolId());
                studentGradeQueryWrapper.inSql("grade_id", "select id from grade where school_id = " + renewClassRecord.getSchoolId() + " and teacher_id = " + renewClassRecord.getTeacherId() + "");
            } else if (type.equals(3)) {
                studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + renewClassRecord.getTeacherId() + "");
            } else if (type.equals(4)) {
                studentGradeQueryWrapper.eq("school_id", renewClassRecord.getSchoolId());
            }

            studentGradeQueryWrapper.eq(StringUtils.isNotBlank(subjectsId), "subjects_id", subjectsId);
            studentGradeQueryWrapper.eq("year_part", quarter.getYearPart());
            studentGradeQueryWrapper.eq("quarter_num", quarter.getNum());
            studentGradeQueryWrapper.notIn("status", 3, 4);//订单作废的不算,转校转出的不算
            studentGradeQueryWrapper.eq("deleted", 0);
            studentGradeQueryWrapper.eq("is_last", 1);
            studentGradeQueryWrapper.ne("is_makeup", 1);//是否补课（跨学期补课，统计率要排除掉）
            if (StringUtils.isNotBlank(yearClassId)) {
                List<String> yearClassList = Arrays.asList(yearClassId.split(","));
                studentGradeQueryWrapper.in("year_class_id", yearClassList);
            }
            if (StringUtils.isNotBlank(gradeSection)) {
                if (gradeSection.equals("0")) {
                    studentGradeQueryWrapper.in("year_class_id", 1, 2);//0, 先不包含0的
                } else if (gradeSection.equals("1")) {
                    studentGradeQueryWrapper.in("year_class_id", 3, 4, 5, 6);
                } else if (gradeSection.equals("2")) {
                    studentGradeQueryWrapper.in("year_class_id", 7, 8, 9);
                } else if (gradeSection.equals("3")) {
                    studentGradeQueryWrapper.in("year_class_id", 10, 11, 12);
                }
            } else {
                studentGradeQueryWrapper.ne("year_class_id", 0);// 先不包含0的
            }

            if (courseTypeId != null) {
                if (courseTypeId.equals("1565023758494501025")) {
                    studentGradeQueryWrapper.eq("course_type_id", 1575859909042028546L);//基础班，精品课为提高班
                } else {
                    studentGradeQueryWrapper.eq("course_type_id", courseTypeId);
                }
                try {
                    if (courseTypeId.equals("1565023758494501025") || courseTypeId.equals("1575859909042028546")) {
                        List<Long> longList = iPlanFeignClient.getStudentIdForClassType(Integer.valueOf(yearPart), Integer.valueOf(quarterNum), 1565023758494501025L);
                        if (courseTypeId.equals("1565023758494501025")) {
                            studentGradeQueryWrapper.in("student_id", longList);
                        }
                        if (courseTypeId.equals("1575859909042028546")) {
                            studentGradeQueryWrapper.notIn("student_id", longList);
                        }
                    }
                } catch (NumberFormatException e) {
                    System.out.println("反查学生id连接异常");
                }
            }

//            if (courseTypeId != null) {
//                String[] strArray = courseTypeId.split(",");
//                Set<String> boutique = new HashSet<>();//精品课
//                Set<String> smart = new HashSet<>();//智能课
//                for (String s : strArray) {
//                    if (s.equals("1565023758494501025") || s.equals("1575859909042028546")) {
//                        boutique.add("1575859909042028546");//智能课基础班，精品课为提高班
//                    } else {
//                        boutique.add(s);
//                    }
//                    smart.add(s);
//                }
//
//                StringBuilder sb = new StringBuilder();
//                for (String uniqueString : boutique) {
//                    sb.append(uniqueString + ",");
//                }
//                String courseTypeStr = sb.toString();
//                courseTypeStr = courseTypeStr.substring(0, courseTypeStr.length() - 1);
//                studentGradeQueryWrapper.inSql("course_type_id", courseTypeStr);
//
//                if (!smart.contains("1565023758494501025") || !smart.contains("1575859909042028546")) {//当基础班和提高班不同时选择
//                    List<Long> longList = iPlanFeignClient.getStudentIdForClassType(Integer.valueOf(yearPart), Integer.valueOf(quarterNum), 1565023758494501025L);
//                    if (smart.contains("1565023758494501025")) {
//                        studentGradeQueryWrapper.in("student_id", longList);//基础班，查询基础班学员
//                    }
//                    if (smart.contains("1575859909042028546") && !smart.contains("1565023758494501025")) {
//                        studentGradeQueryWrapper.notIn("student_id", longList);//提高班，排除基础班学员
//                    }
//                }
//            }

            QueryWrapper<StudentGrade> studentGradeQueryWrapper2 = studentGradeQueryWrapper.clone();
            studentGradeQueryWrapper2.groupBy("student_id");
            studentGradeQueryWrapper2.eq("lesson_type", 1);//1精品课，2智能课，3刷题班
            studentGradeQueryWrapper2.eq("subjects_id", 1);//科目id 1是英语
            List<Long> studentIdList = studentGradeMapper.getGroupByAtNewStudentIdList(studentGradeQueryWrapper2);

            //获取带班总人数
            Integer studentAllCount = renewClassMapper.getStudentAllCount(studentGradeQueryWrapper);
            studyPlan.setAllStudentCount(studentAllCount);

            PlanShutNum planShutNum = new PlanShutNum();
            if (taskState != null) {
                planShutNum.setTaskState(taskState);//1突破目标通关率；为空不传就是原来的“基础目标”最低通关率
            }
            if (passersStatus != null) {
                planShutNum.setPassersStatus(passersStatus);//不传就是原来的关数，传1是人数
            }
            if (taskCourseNum != null) {
                planShutNum.setTaskCourseNum(taskCourseNum);//学习到的课次
            }
            if (taskCourseNumNow != null) {
                planShutNum.setTaskCourseNumNow(taskCourseNumNow);//学习到的课次
            }
            if (taskDateStart != null) {
                planShutNum.setTaskDateStart(taskDateStart);//学习到的课次 开始时间
            }
            if (taskDateEnd != null) {
                planShutNum.setTaskDateEnd(taskDateEnd);//学习到的课次 结束时间
            }
            planShutNum.setYearPart(Integer.parseInt(yearPart));
            planShutNum.setQuarterNum(Integer.parseInt(quarterNum));
            if (StringUtils.isNotBlank(classTypeId)) {
                planShutNum.setClassTypeId(classTypeId);
            }
            if (StringUtils.isNotBlank(yearClassId)) {
                planShutNum.setYearClassId(yearClassId);
            }
            planShutNum.setStudentIdList(studentIdList);
            if (StringUtils.isNotBlank(gradeSection)) {
                planShutNum.setGradeSection(Integer.parseInt(gradeSection));
            }

            JSONObject getMapN = new JSONObject();
            getMapN.put("yearPart", yearPart);
            getMapN.put("quarterNum", quarterNum);
            getMapN.put("yearClassId", yearClassId);
            getMapN.put("gradeSection", gradeSection);
            getMapN.put("classTypeId", classTypeId);
            getMapN.put("studentIdList", studentIdList);
            JSONObject getMap = new JSONObject();
            getMap.put("id", renewClassRecord.getTeacherId());
            getMap.put("name", getMapN);
            objects.add(getMap);
            try {
                Map<String, Object> rsMap = iPlanFeignClient.getMinimumTaskProgressRate(planShutNum);
                if (rsMap != null) {
                    Integer planShutNumAlready = 0;
                    Integer shutNumAll = studentAllCount;
                    Integer planShutNumPass = 0;//学习进度，已通关关数（不大于课程里设置的应通关关数）
                    Integer shutNumShouldPassAll = studentAllCount;

                    if (rsMap.get("planShutNum") != null) {
                        planShutNumAlready = (Integer) rsMap.get("planShutNum");
                    }
                    if (rsMap.get("shutNumAll") != null && passersStatus == null) {
                        shutNumAll = (Integer) rsMap.get("shutNumAll");
                    }
                    if (rsMap.get("planShutNumPass") != null) {
                        planShutNumPass = (Integer) rsMap.get("planShutNumPass");
                    }
                    if (rsMap.get("shutNumShouldPassAll") != null && passersStatus == null) {
                        shutNumShouldPassAll = (Integer) rsMap.get("shutNumShouldPassAll");
                    }

                    studyPlan.setAlreadyShutNum(planShutNumAlready);
                    studyPlan.setAllShutNum(shutNumAll);
                    studyPlan.setPlanShutNumPass(planShutNumPass);
                    studyPlan.setShutNumShouldPassAll(shutNumShouldPassAll);

                    studyPlan.setNotShutNum(shutNumAll - planShutNumAlready);
                    if (planShutNumAlready > shutNumAll) {
                        studyPlan.setNotShutNum(0);
                    }

                    Integer newNumAll = 0;
                    if (rsMap.get("newNumAll") != null) {
                        newNumAll = (Integer) rsMap.get("newNumAll");
                    }
                    studyPlan.setNewNumAll(newNumAll);
                    String studentIdString = "";
                    if (rsMap.get("studentIdString") != null) {
                        studentIdString = rsMap.get("studentIdString").toString();
                    }
                    studyPlan.setStudentIdString(studentIdString);
                }

            } catch (Exception e) {
                studyPlan.setAlreadyShutNum(0);
                studyPlan.setAllShutNum(0);
                studyPlan.setPlanShutNumPass(0);
                studyPlan.setShutNumShouldPassAll(0);
                studyPlan.setNewNumAll(0);
            }
            studyPlanList.add(studyPlan);
        }
        return studyPlanList;
    }

    public IPage<StudyPlan> getMinimumTaskProgressRateDetail(String schoolId, String teacherId, String gradeId, String yearPart, String yearClassId, Integer type, String classTypeId, String subjectsId, String quarterNum, String startDate, String endDate, String trackId, String gradeSection, Integer pageNum, Integer pageSize, Integer passersStatus, Integer taskCourseNum, Integer taskCourseNumNow, Integer taskState, Integer offState, String courseTypeId, String taskDateStart, String taskDateEnd, String studentIdString) {
        IPage<StudyPlan> iPage = new Page<>(pageNum, pageSize);

        Quarter quarter = iQuarterService.getNowQuarter();
        if (StringUtils.isNotBlank(yearPart) && StringUtils.isNotBlank(quarterNum)) {
            quarter.setYearPart(Integer.parseInt(yearPart));
            quarter.setNum(Integer.parseInt(quarterNum));
        }
        QueryWrapper<StudentGrade> studentGradeQueryWrapper = new QueryWrapper<>();
        studentGradeQueryWrapper.eq("subjects_id", subjectsId);
        if (StringUtils.isNotBlank(gradeId)) {
            studentGradeQueryWrapper.eq("grade_id", gradeId);
        }
        //1老师，2校区老师，3校长，4校区
        if (type.equals(1)) {
            studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + teacherId + "");
        } else if (type.equals(2)) {
            studentGradeQueryWrapper.eq("school_id", schoolId);
            studentGradeQueryWrapper.inSql("grade_id", "select id from grade where school_id = " + schoolId + " and teacher_id = " + teacherId + "");

        } else if (type.equals(3)) {
            studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + teacherId + "");
        } else if (type.equals(4)) {
            studentGradeQueryWrapper.eq("school_id", schoolId);
        }

        studentGradeQueryWrapper.eq(StringUtils.isNotBlank(subjectsId), "subjects_id", subjectsId);
        studentGradeQueryWrapper.eq("year_part", quarter.getYearPart());
        studentGradeQueryWrapper.eq("quarter_num", quarter.getNum());
        studentGradeQueryWrapper.notIn("status", 3, 4);//订单作废的不算,转校转出的不算
        studentGradeQueryWrapper.eq("deleted", 0);
        studentGradeQueryWrapper.eq("is_last", 1);
        studentGradeQueryWrapper.eq("lesson_type", 1);//1精品课，2智能课，3刷题班
        studentGradeQueryWrapper.ne("is_makeup", 1);
        if (StringUtils.isNotBlank(yearClassId)) {
            List<String> yearClassList = Arrays.asList(yearClassId.split(","));
            studentGradeQueryWrapper.in("year_class_id", yearClassList);
        }
        if (StringUtils.isNotBlank(gradeSection)) {
            if (gradeSection.equals("0")) {
                studentGradeQueryWrapper.in("year_class_id", 1, 2);//0, 先不包含0的
            } else if (gradeSection.equals("1")) {
                studentGradeQueryWrapper.in("year_class_id", 3, 4, 5, 6);
            } else if (gradeSection.equals("2")) {
                studentGradeQueryWrapper.in("year_class_id", 7, 8, 9);
            } else if (gradeSection.equals("3")) {
                studentGradeQueryWrapper.in("year_class_id", 10, 11, 12);
            }
        } else {
            studentGradeQueryWrapper.ne("year_class_id", 0);// 先不包含0的
        }

        QueryWrapper<StudentGrade> studentGradeQueryWrapper2 = studentGradeQueryWrapper.clone();
        studentGradeQueryWrapper2.groupBy("student_id");
        if (courseTypeId != null) {
            if (courseTypeId.equals("1565023758494501025")) {
                studentGradeQueryWrapper2.eq("course_type_id", 1575859909042028546L);//基础班，精品课为提高班
            } else {
                studentGradeQueryWrapper2.eq("course_type_id", courseTypeId);
            }
            if (studentIdString == null) {
                try {
                    if (courseTypeId.equals("1565023758494501025") || courseTypeId.equals("1575859909042028546")) {
                        List<Long> longList = iPlanFeignClient.getStudentIdForClassType(Integer.valueOf(yearPart), Integer.valueOf(quarterNum), 1565023758494501025L);
                        if (courseTypeId.equals("1565023758494501025")) {
                            studentGradeQueryWrapper2.in("student_id", longList);
                        }
                        if (courseTypeId.equals("1575859909042028546")) {
                            studentGradeQueryWrapper2.notIn("student_id", longList);
                        }
                    }
                } catch (NumberFormatException e) {
                    System.out.println("反查学生id连接异常");
                }
            }
        }
        if (studentIdString != null) {
            if (studentIdString.equals("0")) {
                studentGradeQueryWrapper2.eq("student_id", 0);
            } else {
                studentGradeQueryWrapper2.in("student_id", studentIdString.split(","));
            }
        }
        studentGradeMapper.getGroupByAtNewStudentList(iPage, studentGradeQueryWrapper2);

        for (StudyPlan studyPlan : iPage.getRecords()) {
            //获取带班总人数
            Student student = iStudentService.getById(studyPlan.getStudentId());
            if (student == null)
                continue;
            Grade grade = iGradeService.getById(studyPlan.getGradeId());
            if (grade != null) {
                studyPlan.setYearClassName(CommonUtil.getYearClassNameForId(grade.getYearClassId().getKey()));
                CourseType courseType = iCourseTypeService.getById(grade.getCourseTypeId());
                studyPlan.setClassTypeName(courseType.getName());
            }

            studyPlan.setStudentName(student.getName());

            PlanShutNum planShutNum = new PlanShutNum();
            planShutNum.setYearClassId(String.valueOf(grade.getYearClassId().getKey()));
            if (taskState != null) {
                planShutNum.setTaskState(taskState);//1突破目标通关率；为空不传就是原来的“基础目标”最低通关率
            }
            if (passersStatus != null) {
                planShutNum.setPassersStatus(passersStatus);//不传就是原来的关数，传1是人数
            }
            if (taskCourseNum != null) {
                planShutNum.setTaskCourseNum(taskCourseNum);//学习到的课次
            }
            if (taskDateStart != null) {
                planShutNum.setTaskDateStart(taskDateStart);//学习到的课次 开始时间
            }
            if (taskDateEnd != null) {
                planShutNum.setTaskDateEnd(taskDateEnd);//学习到的课次 结束时间
            }
            if (taskCourseNumNow != null) {
                planShutNum.setTaskCourseNumNow(taskCourseNumNow);//学习到的课次
            }
            planShutNum.setYearPart(Integer.parseInt(yearPart));
            planShutNum.setQuarterNum(Integer.parseInt(quarterNum));
            if (StringUtils.isNotBlank(classTypeId)) {
                planShutNum.setClassTypeId(classTypeId);
            }

            Long studentId = studyPlan.getStudentId();
            List<Long> stuList = new ArrayList<Long>();
            stuList.add(studentId);
            planShutNum.setStudentIdList(stuList);
            planShutNum.setIsDetails(1);//是详情页？1是，其他为否
            if (StringUtils.isNotBlank(gradeSection)) {
                planShutNum.setGradeSection(Integer.parseInt(gradeSection));
            }

            try {
                Map<String, Object> rsMap = iPlanFeignClient.getMinimumTaskProgressRate(planShutNum);
                Integer planShutNumAlready = 0;
                Integer shutNumAll = 0;
                Integer schedule = 0;
                Integer planShutNumPass = 0;//学习进度，已通关关数（不大于课程里设置的应通关关数）
                Integer shutNumShouldPassAll = 0;
                if (rsMap.get("planShutNum") != null) {
                    planShutNumAlready = (Integer) rsMap.get("planShutNum");
                }
                if (rsMap.get("shutNumAll") != null) {
                    shutNumAll = (Integer) rsMap.get("shutNumAll");
                }
                if (rsMap.get("planShutNumPass") != null) {
                    planShutNumPass = (Integer) rsMap.get("planShutNumPass");
                }
                if (rsMap.get("shutNumShouldPassAll") != null) {
                    shutNumShouldPassAll = (Integer) rsMap.get("shutNumShouldPassAll");
                }
                if (rsMap.get("schedule") != null) {
                    schedule = (Integer) rsMap.get("schedule");
                }

                studyPlan.setAlreadyShutNum(planShutNumAlready);
                studyPlan.setAllShutNum(shutNumAll);
                studyPlan.setSchedule(schedule);
                studyPlan.setPlanShutNumPass(planShutNumPass);
                studyPlan.setShutNumShouldPassAll(shutNumShouldPassAll);
                studyPlan.setNotShutNum(shutNumAll - planShutNumAlready);
                if (planShutNumAlready > shutNumAll) {
                    studyPlan.setNotShutNum(0);
                }
            } catch (Exception e) {
                System.out.println("连接异常");
                System.out.println(e.getMessage());
            }
        }

        return iPage;
    }

    @Override
    public List<ArrivalRate> getSuspensionRate(Map<String, String> reMap, List<Long> baseSchoolIdList) {
        String yearPart = reMap.get("yearPart");
        String schoolId = reMap.get("schoolId");
        String yearClassId = reMap.get("yearClassId");
        String classTypeId = reMap.get("classTypeId");
        String startDate = reMap.get("startDate");
        String quarterNum = reMap.get("quarterNum");
        String endDate = reMap.get("endDate");
        String subjectsId = reMap.get("subjectsId");
        String type = reMap.get("type");
        String lessonType = "1";
        if (reMap.get("lessonType") != null) {
            lessonType = reMap.get("lessonType");
        }

        Quarter quarterNow = iQuarterService.getNowQuarter();
        //是否查看历史的，1是，0否
        Integer isHistory = 0;
        if (!String.valueOf(quarterNow.getYearPart()).equals(yearPart) || !String.valueOf(quarterNow.getNum()).equals(quarterNum)) {
            isHistory = 1;
        }

        if (StringUtils.isBlank(schoolId)) {
            if (type.equals("2")) {
                //校区老师状态，只能看自己所在校区的数据
                schoolId = baseSchoolIdList.stream().map(Object::toString).collect(Collectors.joining(","));
            }
        }

        List<ArrivalRate> suspensionRate = studentGradeMapper.getSuspensionRate(classTypeId, yearClassId, yearPart, quarterNum, schoolId, subjectsId, startDate, endDate, type, lessonType, isHistory);
//        for (ArrivalRate arrivalRate: suspensionRate) {
//            //停课学员
//            String teacherId = null;
//            String schoolIdString = schoolId;
//            if (Objects.equals(type, "4")) {
//                schoolIdString = arrivalRate.getSchoolId().toString();
//            } else {
//                teacherId = arrivalRate.getTeacherId().toString();
//            }
//            if (Objects.equals(type, "2")) {
//                schoolIdString = arrivalRate.getSchoolId().toString();
//                teacherId = arrivalRate.getTeacherId().toString();
//            }
//            Integer integer1 = studentGradeMapper.DiscontinuedStudentsCount(yearPart, quarterNum, schoolIdString, teacherId, null, subjectsId, startDate, endDate, type, lessonType);
//            arrivalRate.setSuspendClassesCount(integer1);
//        }
        return suspensionRate;
    }

    public List<ArrivalRate> getSuspensionRateDetail(Map<String, String> reMap) {
        String yearPart = reMap.get("yearPart");
        String schoolId = reMap.get("schoolId");
        String startDate = reMap.get("startDate");
        String quarterNum = reMap.get("quarterNum");
        String yearClassId = reMap.get("yearClassId");
        String classTypeId = reMap.get("classTypeId");
        String endDate = reMap.get("endDate");
        String subjectsId = reMap.get("subjectsId");
        String type = reMap.get("type");
        String lessonType = "1";
        if (reMap.get("lessonType") != null) {
            lessonType = reMap.get("lessonType");
        }
        String teacherId = reMap.get("teacherId");
        String gradeId = reMap.get("gradeId");

        Quarter quarterNow = iQuarterService.getNowQuarter();
        Integer isHistory = 0;
        if (!String.valueOf(quarterNow.getYearPart()).equals(yearPart) || !String.valueOf(quarterNow.getNum()).equals(quarterNum)) {
            isHistory = 1;
        }
        return studentGradeMapper.getSuspensionRateDetail(classTypeId, yearClassId, yearPart, quarterNum, schoolId, teacherId, gradeId, subjectsId, startDate, endDate, type, lessonType, isHistory);
    }

    public ArrayList<Object> getTaskNumber(EduTask eduTask) {
        try {
            List<EduTask> taskNumber = iPlanFeignClient.getTaskNumber(eduTask);
            ArrayList<Object> objects = new ArrayList<>();
            for (EduTask eduTask1 : taskNumber) {
                objects.add(eduTask1.getTaskCourseNum());
            }
            return objects;
        } catch (Exception e) {
//            throw new RuntimeException(e);
            return null;
        }
    }

    public ArrayList<Object> getTaskDate(EduTask eduTask) {
        try {
            List<EduTask> taskNumber = iPlanFeignClient.getTaskNumber(eduTask);
            ArrayList<Object> objects = new ArrayList<>();
            for (EduTask eduTask1 : taskNumber) {
                HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
                objectObjectHashMap.put("taskCourseNum", eduTask1.getTaskCourseNum());
                objectObjectHashMap.put("taskDate", eduTask1.getTaskDate());
                objects.add(objectObjectHashMap);
            }
            return objects;
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public Map<String, Object> getTaskNew(String yearPart, String quarterNum, String yearClassId, String classTypeId, String courseVersionId) {
        return iPlanFeignClient.getTaskNew(yearPart, quarterNum, yearClassId, classTypeId, courseVersionId);
    }

    @Async
    @Override
    public void synchronousStudentIdForClassType() {
        //获取所有学员
        QueryWrapper<StudentGrade> studentGradeQueryWrapper = new QueryWrapper<>();
        studentGradeQueryWrapper.eq("lesson_type", 1);
        studentGradeQueryWrapper.orderByAsc("created_at");
        studentGradeQueryWrapper.groupBy("student_id,grade_id");
        List<StudentGrade> list = iStudentGradeService.list(studentGradeQueryWrapper);
        for (StudentGrade studentGrade : list) {
            //初起化同步内容
            com.xmy.cultivate.respons.StudentClassType studentClassType = new com.xmy.cultivate.respons.StudentClassType();
            studentClassType.setStudentId(studentGrade.getStudentId());
            studentClassType.setSchoolId(studentGrade.getSchoolId());
            studentClassType.setGradeId(studentGrade.getGradeId());
            studentClassType.setQuarterNum(studentGrade.getQuarterNum());
            studentClassType.setYearClassId(studentGrade.getYearClassId());
            studentClassType.setYearPart(studentGrade.getYearPart());
            studentClassType.setIsBoutique(1);
            //获取班级
            Grade gradeServiceOne = iGradeService.getById(studentGrade.getGradeId());
            if (gradeServiceOne != null) {
                studentClassType.setClassTypeId(gradeServiceOne.getCourseTypeId());
                studentClassType.setTeacherId(gradeServiceOne.getTeacherId());
            }
            //获取年级
            studentClassType.setGradeSection(CommonUtil.getGradeSection(studentGrade.getYearClassId()));
            try {
                //发起 同步 处理
                iPlanFeignClient.synchronousStudentIdForClassType(studentClassType);
            } catch (Exception e) {
//                throw new RuntimeException(e);
            }
        }
    }

    @Override
    public List<StudyPlan> getClearanceRateChaPlan(Map<String, Object> reMap) {
        String schoolId = reMap.get("schoolId") != null && !reMap.get("schoolId").toString().isEmpty() ? reMap.get("schoolId").toString() : null;
        String yearPart = reMap.get("yearPart") != null && !reMap.get("yearPart").toString().isEmpty() ? reMap.get("yearPart").toString() : null;
        String yearClassId = reMap.get("yearClassId") != null && !reMap.get("yearClassId").toString().isEmpty() ? reMap.get("yearClassId").toString() : null;
        Integer type = reMap.get("type") != null && !reMap.get("type").toString().isEmpty() ? Integer.parseInt(reMap.get("type").toString()) : 1;
        String classTypeId = reMap.get("classTypeId") != null && !reMap.get("classTypeId").toString().isEmpty() ? reMap.get("classTypeId").toString() : null;
        String quarterNum = reMap.get("quarterNum") != null && !reMap.get("quarterNum").toString().isEmpty() ? reMap.get("quarterNum").toString() : null;
        String gradeSection = reMap.get("gradeSection") != null && !reMap.get("gradeSection").toString().isEmpty() ? reMap.get("gradeSection").toString() : null;
        Integer passersStatus = reMap.get("passersStatus") != null && !reMap.get("passersStatus").toString().isEmpty() ? Integer.valueOf(reMap.get("passersStatus").toString()) : null;
        Integer taskCourseNum = reMap.get("taskCourseNum") != null && !reMap.get("taskCourseNum").toString().isEmpty() ? Integer.valueOf(reMap.get("taskCourseNum").toString()) : null;
        Integer taskState = reMap.get("taskState") != null && !reMap.get("taskState").toString().isEmpty() ? Integer.valueOf(reMap.get("taskState").toString()) : null;
        String courseTypeId = reMap.get("courseTypeId") != null && !reMap.get("courseTypeId").toString().isEmpty() ? reMap.get("courseTypeId").toString() : null;
        String taskDateStart = reMap.get("taskDateStart") != null && !reMap.get("taskDateStart").toString().isEmpty() ? reMap.get("taskDateStart").toString() : null;
        String taskDateEnd = reMap.get("taskDateEnd") != null && !reMap.get("taskDateEnd").toString().isEmpty() ? reMap.get("taskDateEnd").toString() : null;
        String subjectsId = "1";
        Quarter quarter = iQuarterService.getNowQuarter();
        if (StringUtils.isNotBlank(yearPart) && StringUtils.isNotBlank(quarterNum)) {
            quarter.setYearPart(Integer.parseInt(yearPart));
            quarter.setNum(Integer.parseInt(quarterNum));
        }

        QueryWrapper queryWrapper = new QueryWrapper();

        queryWrapper.eq(StringUtils.isNotBlank(subjectsId), "subjects_id", subjectsId);
        queryWrapper.eq("lesson_type", 1);
        queryWrapper.eq("year_part", quarter.getYearPart());
        queryWrapper.eq("quarter_num", quarter.getNum());
        queryWrapper.eq("deleted", 0);

        if (StringUtils.isNotBlank(yearClassId)) {
            //queryWrapper.eq("year_class_id", yearClassId);
            List<String> yearClassList = Arrays.asList(yearClassId.split(","));
            queryWrapper.in("year_class_id", yearClassList);
        }
        if (StringUtils.isNotBlank(gradeSection)) {
            if (gradeSection.equals("0")) {
                queryWrapper.in("year_class_id", 1, 2);//0, 先不包含0的
            } else if (gradeSection.equals("1")) {
                queryWrapper.in("year_class_id", 3, 4, 5, 6);
            } else if (gradeSection.equals("2")) {
                queryWrapper.in("year_class_id", 7, 8, 9);
            } else if (gradeSection.equals("3")) {
                queryWrapper.in("year_class_id", 10, 11, 12);
            }
        } else {
            queryWrapper.ne("year_class_id", 0);// 先不包含0的
        }


        List<StudyPlan> studyPlanList = new ArrayList<>();
        List<RenewClassRecord> renewClassRecordList = null;

        List<String> groupBys = new ArrayList<>();
        //1老师，2校区老师，3校长，4校区
        if (type.equals(1)) {
            groupBys.add("teacher_id");
        } else if (type.equals(2)) {
            queryWrapper.eq(StringUtils.isNotBlank(schoolId), "school_id", schoolId);
            groupBys.add("school_id");
            groupBys.add("teacher_id");
        } else if (type.equals(3)) {
            queryWrapper.inSql("teacher_id", "select admin_id from role_admin where role_id = 1568160887369994242 ");
            groupBys.add("teacher_id");

        } else if (type.equals(4)) {
            groupBys.add("school_id");
        }
        groupBys.add("quarter_num");
        if (StringUtils.isNotBlank(subjectsId)) {
            groupBys.add("subjects_id");
        }

        queryWrapper.groupBy(groupBys);

        if (type.equals(1)) {
            renewClassRecordList = renewClassMapper.getRenewRecordPerson(queryWrapper);
        } else if (type.equals(2)) {
            renewClassRecordList = renewClassMapper.getRenewRecord(queryWrapper);
        } else if (type.equals(3)) {
            renewClassRecordList = renewClassMapper.getRenewRecordPerson(queryWrapper);
        } else if (type.equals(4)) {
            renewClassRecordList = renewClassMapper.getRenewRecordSchool(queryWrapper);
        }

        if (renewClassRecordList != null) {
            for (RenewClassRecord renewClassRecord : renewClassRecordList) {

                StudyPlan studyPlan = new StudyPlan();
                BeanUtils.copyProperties(renewClassRecord, studyPlan);
                studyPlan.setSchoolId(renewClassRecord.getSchoolId());
                studyPlan.setTeacherId(renewClassRecord.getTeacherId());

                QueryWrapper<StudentGrade> studentGradeQueryWrapper = new QueryWrapper<>();
                studentGradeQueryWrapper.eq("lesson_type", 1);
                studentGradeQueryWrapper.eq("subjects_id", subjectsId);

                //1老师，2校区老师，3校长，4校区
                if (type.equals(1)) {
                    studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + renewClassRecord.getTeacherId() + "");
                } else if (type.equals(2)) {
                    studentGradeQueryWrapper.eq("school_id", renewClassRecord.getSchoolId());
                    studentGradeQueryWrapper.inSql("grade_id", "select id from grade where school_id = " + renewClassRecord.getSchoolId() + " and teacher_id = " + renewClassRecord.getTeacherId() + "");
                } else if (type.equals(3)) {
                    studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + renewClassRecord.getTeacherId() + "");
                } else if (type.equals(4)) {
                    studentGradeQueryWrapper.eq("school_id", renewClassRecord.getSchoolId());
                }

                studentGradeQueryWrapper.eq(StringUtils.isNotBlank(subjectsId), "subjects_id", subjectsId);
                studentGradeQueryWrapper.eq("year_part", quarter.getYearPart());
                studentGradeQueryWrapper.eq("quarter_num", quarter.getNum());
                studentGradeQueryWrapper.notIn("status", 3, 4);//订单作废的不算,转校转出的不算
                studentGradeQueryWrapper.eq("deleted", 0);
                studentGradeQueryWrapper.eq("is_last", 1);
                studentGradeQueryWrapper.ne("is_makeup", 1);//是否补课（跨学期补课，统计率要排除掉）
                if (StringUtils.isNotBlank(yearClassId)) {
                    studentGradeQueryWrapper.eq("year_class_id", yearClassId);
                }
                if (StringUtils.isNotBlank(gradeSection)) {
                    switch (gradeSection) {
                        case "0":
                            studentGradeQueryWrapper.in("year_class_id", 1, 2);//0, 先不包含0的

                            break;
                        case "1":
                            studentGradeQueryWrapper.in("year_class_id", 3, 4, 5, 6);
                            break;
                        case "2":
                            studentGradeQueryWrapper.in("year_class_id", 7, 8, 9);
                            break;
                        case "3":
                            studentGradeQueryWrapper.in("year_class_id", 10, 11, 12);
                            break;
                    }
                } else {
                    studentGradeQueryWrapper.ne("year_class_id", 0);// 先不包含0的
                }
                if (courseTypeId != null) {
                    if (courseTypeId.equals("1565023758494501025")) {
                        studentGradeQueryWrapper.eq("course_type_id", 1575859909042028546L);//基础班，精品课为提高班
                    } else {
                        studentGradeQueryWrapper.eq("course_type_id", courseTypeId);
                    }
                    try {
                        if (courseTypeId.equals("1565023758494501025") || courseTypeId.equals("1575859909042028546")) {
                            List<Long> longList = null;
                            if (yearPart != null && quarterNum != null) {
                                longList = iPlanFeignClient.getStudentIdForClassType(Integer.valueOf(yearPart), Integer.valueOf(quarterNum), 1565023758494501025L);
                            }
                            if (courseTypeId.equals("1565023758494501025")) {
                                studentGradeQueryWrapper.in("student_id", longList);
                            }
                            if (courseTypeId.equals("1575859909042028546")) {
                                studentGradeQueryWrapper.notIn("student_id", longList);
                            }
                        }
                    } catch (NumberFormatException e) {
                        System.out.println("反查学生id连接异常");
                    }
                }
                QueryWrapper<StudentGrade> studentGradeQueryWrapper2 = studentGradeQueryWrapper.clone();
                studentGradeQueryWrapper2.groupBy("student_id");
                studentGradeQueryWrapper2.eq("lesson_type", 1);//1精品课，2智能课，3刷题班
                studentGradeQueryWrapper2.eq("subjects_id", 1);//科目id 1是英语

                List<Long> studentIdList = studentGradeMapper.getGroupByAtNewStudentIdList(studentGradeQueryWrapper2);

                //获取带班总人数
                Integer studentAllCount = renewClassMapper.getStudentAllCount(studentGradeQueryWrapper);
                studyPlan.setAllStudentCount(studentAllCount);

                PlanShutNum planShutNum = new PlanShutNum();
                if (taskState != null) {
                    planShutNum.setTaskState(taskState);//1突破目标通关率；为空不传就是原来的“基础目标”最低通关率
                }
                if (passersStatus != null) {
                    planShutNum.setPassersStatus(passersStatus);//不传就是原来的关数，传1是人数
                }
                if (taskCourseNum != null) {
                    planShutNum.setTaskCourseNum(taskCourseNum);//学习到的课次
                }
                if (taskDateStart != null) {
                    planShutNum.setTaskDateStart(taskDateStart);//学习到的课次 开始时间
                }
                if (taskDateEnd != null) {
                    planShutNum.setTaskDateEnd(taskDateEnd);//学习到的课次 结束时间
                }
                if (yearPart != null) {
                    planShutNum.setYearPart(Integer.parseInt(yearPart));
                }
                if (quarterNum != null) {
                    planShutNum.setQuarterNum(Integer.parseInt(quarterNum));
                }
                if (StringUtils.isNotBlank(classTypeId))
                    planShutNum.setClassTypeId(classTypeId);
                if (StringUtils.isNotBlank(yearClassId))
                    planShutNum.setYearClassId(yearClassId);
                planShutNum.setStudentIdList(studentIdList);
                if (StringUtils.isNotBlank(gradeSection))
                    planShutNum.setGradeSection(Integer.parseInt(gradeSection));

                try {
                    ChaPlan clearanceRateChaPlan = iMathematicsFeignClient.getClearanceRateChaPlan(planShutNum);
                    //                Integer planShutNumAlready = (Integer) rsMap.get("planShutNum");//已通关关数
                    //                Integer shutNumAll = (Integer) rsMap.get("shutNumAll");//总关数
                    //                Integer planShutNumPass = (Integer) rsMap.get("planShutNumPass");//学习进度，已通关关数（不大于课程里设置的应通关关数）
                    //                Integer shutNumShouldPassAll = (Integer) rsMap.get("shutNumShouldPassAll");

                    studyPlan.setAlreadyShutNum(clearanceRateChaPlan.getRightNum());//应通关-正确题数 改成 已通关关数
                    studyPlan.setAllShutNum(clearanceRateChaPlan.getLowestShutnum());//应通关数
                    studyPlan.setPlanShutNumPass(clearanceRateChaPlan.getAmendNum());//应通关-修正题数 改成 未通关关数
                    studyPlan.setShutNumShouldPassAll(clearanceRateChaPlan.getLessonNum());//总人数
                    studyPlan.setNotShutNum(clearanceRateChaPlan.getLowestShutnum() - clearanceRateChaPlan.getRightNum());//未通关

                } catch (Exception e) {
                    //System.out.println("连接异常");
                    //System.out.println(e.getMessage());
                    studyPlan.setAlreadyShutNum(0);
                    studyPlan.setAllShutNum(0);
                    studyPlan.setPlanShutNumPass(0);
                    studyPlan.setShutNumShouldPassAll(0);
                    studyPlan.setNewNumAll(0);
                }
                studyPlanList.add(studyPlan);
            }
        }
        return studyPlanList;
    }

    public IPage<StudyPlan> getClearanceRateChaPlanDetail(Map<String, Object> reMap) {
        int pageNum = StringUtils.isEmpty((String) reMap.get("pageNum")) ? 1 : Integer.parseInt((String) reMap.get("pageNum"));
        int pageSize = StringUtils.isEmpty((String) reMap.get("pageSize")) ? 20 : Integer.parseInt((String) reMap.get("pageSize"));

        String schoolId = reMap.get("schoolId") != null && !reMap.get("schoolId").toString().isEmpty() ? reMap.get("schoolId").toString() : null;
        String yearPart = reMap.get("yearPart") != null && !reMap.get("yearPart").toString().isEmpty() ? reMap.get("yearPart").toString() : null;
        String yearClassId = reMap.get("yearClassId") != null && !reMap.get("yearClassId").toString().isEmpty() ? reMap.get("yearClassId").toString() : null;
        Integer type = reMap.get("type") != null && !reMap.get("type").toString().isEmpty() ? Integer.parseInt(reMap.get("type").toString()) : 1;
        String classTypeId = reMap.get("classTypeId") != null && !reMap.get("classTypeId").toString().isEmpty() ? reMap.get("classTypeId").toString() : null;
        String quarterNum = reMap.get("quarterNum") != null && !reMap.get("quarterNum").toString().isEmpty() ? reMap.get("quarterNum").toString() : null;
        String gradeSection = reMap.get("gradeSection") != null && !reMap.get("gradeSection").toString().isEmpty() ? reMap.get("gradeSection").toString() : null;
        Integer passersStatus = reMap.get("passersStatus") != null && !reMap.get("passersStatus").toString().isEmpty() ? Integer.valueOf(reMap.get("passersStatus").toString()) : null;
        Integer taskCourseNum = reMap.get("taskCourseNum") != null && !reMap.get("taskCourseNum").toString().isEmpty() ? Integer.valueOf(reMap.get("taskCourseNum").toString()) : null;
        Integer taskState = reMap.get("taskState") != null && !reMap.get("taskState").toString().isEmpty() ? Integer.valueOf(reMap.get("taskState").toString()) : null;
        String courseTypeId = reMap.get("courseTypeId") != null && !reMap.get("courseTypeId").toString().isEmpty() ? reMap.get("courseTypeId").toString() : null;
        String taskDateStart = reMap.get("taskDateStart") != null && !reMap.get("taskDateStart").toString().isEmpty() ? reMap.get("taskDateStart").toString() : null;
        String taskDateEnd = reMap.get("taskDateEnd") != null && !reMap.get("taskDateEnd").toString().isEmpty() ? reMap.get("taskDateEnd").toString() : null;

        String gradeId = reMap.get("gradeId") != null && !reMap.get("gradeId").toString().isEmpty() ? reMap.get("gradeId").toString() : null;
        String teacherId = reMap.get("teacherId") != null && !reMap.get("teacherId").toString().isEmpty() ? reMap.get("teacherId").toString() : null;

        String subjectsId = "1";

        //新列 用户
        String studentIdString = null;
        if (reMap.get("studentIdString") != null) {
            String studentId = "0";
            if (!Objects.equals(reMap.get("studentIdString"), "")) {
                studentId = reMap.get("studentIdString").toString();
            }
            studentIdString = studentId;
        }


        IPage<StudyPlan> iPage = new Page<>(pageNum, pageSize);

        Quarter quarter = iQuarterService.getNowQuarter();
        if (StringUtils.isNotBlank(yearPart) && StringUtils.isNotBlank(quarterNum)) {
            quarter.setYearPart(Integer.parseInt(yearPart));
            quarter.setNum(Integer.parseInt(quarterNum));
        }

        QueryWrapper<StudentGrade> studentGradeQueryWrapper = new QueryWrapper<>();
        studentGradeQueryWrapper.eq("subjects_id", subjectsId);

        if (StringUtils.isNotBlank(gradeId)) {
            studentGradeQueryWrapper.eq("grade_id", gradeId);
        }
        //1老师，2校区老师，3校长，4校区
        if (type.equals(1)) {
            studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + teacherId);
        } else if (type.equals(2)) {
            studentGradeQueryWrapper.eq("school_id", schoolId);
            studentGradeQueryWrapper.inSql("grade_id", "select id from grade where school_id = " + schoolId + " and teacher_id = " + teacherId);

        } else if (type.equals(3)) {
            studentGradeQueryWrapper.inSql("grade_id", "select id from grade where teacher_id = " + teacherId);
        } else if (type.equals(4)) {
            studentGradeQueryWrapper.eq("school_id", schoolId);
        }

        studentGradeQueryWrapper.eq(StringUtils.isNotBlank(subjectsId), "subjects_id", subjectsId);
        studentGradeQueryWrapper.eq("year_part", quarter.getYearPart());
        studentGradeQueryWrapper.eq("quarter_num", quarter.getNum());
        studentGradeQueryWrapper.notIn("status", 3, 4);//订单作废的不算,转校转出的不算
        studentGradeQueryWrapper.eq("deleted", 0);
        studentGradeQueryWrapper.eq("is_last", 1);
        studentGradeQueryWrapper.eq("lesson_type", 1);//1精品课，2智能课，3刷题班
        studentGradeQueryWrapper.ne("is_makeup", 1);
        if (StringUtils.isNotBlank(yearClassId)) {
            studentGradeQueryWrapper.eq("year_class_id", yearClassId);
        }
        if (StringUtils.isNotBlank(gradeSection)) {
            switch (gradeSection) {
                case "0":
                    studentGradeQueryWrapper.in("year_class_id", 1, 2);//0, 先不包含0的

                    break;
                case "1":
                    studentGradeQueryWrapper.in("year_class_id", 3, 4, 5, 6);
                    break;
                case "2":
                    studentGradeQueryWrapper.in("year_class_id", 7, 8, 9);
                    break;
                case "3":
                    studentGradeQueryWrapper.in("year_class_id", 10, 11, 12);
                    break;
            }
        } else {
            studentGradeQueryWrapper.ne("year_class_id", 0);// 先不包含0的
        }

        QueryWrapper<StudentGrade> studentGradeQueryWrapper2 = studentGradeQueryWrapper.clone();
        studentGradeQueryWrapper2.groupBy("student_id");
        if (courseTypeId != null) {
            if (courseTypeId.equals("1565023758494501025")) {
                studentGradeQueryWrapper2.eq("course_type_id", 1575859909042028546L);//基础班，精品课为提高班
            } else {
                studentGradeQueryWrapper2.eq("course_type_id", courseTypeId);
            }
            if (studentIdString == null) {
                try {
                    if (courseTypeId.equals("1565023758494501025") || courseTypeId.equals("1575859909042028546")) {
                        List<Long> longList = null;
                        if (yearPart != null && quarterNum != null) {
                            longList = iPlanFeignClient.getStudentIdForClassType(Integer.valueOf(yearPart), Integer.valueOf(quarterNum), 1565023758494501025L);
                        }
                        if (courseTypeId.equals("1565023758494501025")) {
                            studentGradeQueryWrapper2.in("student_id", longList);
                        }
                        if (courseTypeId.equals("1575859909042028546")) {
                            studentGradeQueryWrapper2.notIn("student_id", longList);
                        }
                    }
                } catch (NumberFormatException e) {
                    System.out.println("反查学生id连接异常");
                }
            }
        }
        if (studentIdString != null) {
            if (studentIdString.equals("0")) {
                studentGradeQueryWrapper2.eq("student_id", 0);
            } else {
                studentGradeQueryWrapper2.in("student_id", studentIdString.split(","));
            }
        }
        studentGradeMapper.getGroupByAtNewStudentList(iPage, studentGradeQueryWrapper2);

//        List<StudyPlan> studyPlanList = iPage.getRecords();

        for (StudyPlan studyPlan : iPage.getRecords()) {
            //获取带班总人数
            //Integer studentAllCount = renewClassMapper.getStudentAllCount(studentGradeQueryWrapper);
            //studyPlan.setAllStudentCount(studentAllCount);
            Student student = iStudentService.getById(studyPlan.getStudentId());
            if (student == null)
                continue;
            Grade grade = iGradeService.getById(studyPlan.getGradeId());
            if (grade != null) {
                studyPlan.setYearClassName(CommonUtil.getYearClassNameForId(grade.getYearClassId().getKey()));
                CourseType courseType = iCourseTypeService.getById(grade.getCourseTypeId());
                studyPlan.setClassTypeName(courseType.getName());
            }

            studyPlan.setStudentName(student.getName());

            PlanShutNum planShutNum = new PlanShutNum();
//            if (offState != null) {//丢给前端做了，这里先不处理
//                planShutNum.setOffState(offState);//状态 1已通关；2未通关；空全部
//            }
            if (taskState != null) {
                planShutNum.setTaskState(taskState);//1突破目标通关率；为空不传就是原来的“基础目标”最低通关率
            }
            if (passersStatus != null) {
                planShutNum.setPassersStatus(passersStatus);//不传就是原来的关数，传1是人数
            }
            if (taskCourseNum != null) {
                planShutNum.setTaskCourseNum(taskCourseNum);//学习到的课次
            }
            if (taskDateStart != null) {
                planShutNum.setTaskDateStart(taskDateStart);//学习到的课次 开始时间
            }
            if (yearPart != null) {
                planShutNum.setYearPart(Integer.parseInt(yearPart));
            }
            if (quarterNum != null) {
                planShutNum.setQuarterNum(Integer.parseInt(quarterNum));
            }
            if (StringUtils.isNotBlank(classTypeId)) {
                planShutNum.setClassTypeId(classTypeId);
            }
            if (StringUtils.isNotBlank(yearClassId)) {
                planShutNum.setYearClassId(yearClassId);
            }

            Long studentId = studyPlan.getStudentId();
            List<Long> stuList = new ArrayList<Long>();
            stuList.add(studentId);
            planShutNum.setStudentIdList(stuList);
            if (StringUtils.isNotBlank(gradeSection))
                planShutNum.setGradeSection(Integer.parseInt(gradeSection));
            try {

                ChaPlan clearanceRateChaPlan = iMathematicsFeignClient.getClearanceRateChaPlan(planShutNum);

                studyPlan.setAlreadyShutNum(clearanceRateChaPlan.getRightNum());//应通关-正确题数 改成 已通关关数
                studyPlan.setAllShutNum(clearanceRateChaPlan.getLowestShutnum());//应通关数
                studyPlan.setPlanShutNumPass(clearanceRateChaPlan.getAmendNum());//应通关-修正题数 改成 未通关关数
                studyPlan.setShutNumShouldPassAll(clearanceRateChaPlan.getLessonNum());//总人数
                studyPlan.setNotShutNum(clearanceRateChaPlan.getLowestShutnum() - clearanceRateChaPlan.getRightNum());//未通关

            } catch (Exception e) {
//                System.out.println("连接异常");
//                System.out.println(e.getMessage());
                studyPlan.setAlreadyShutNum(0);
                studyPlan.setAllShutNum(0);
                studyPlan.setPlanShutNumPass(0);
                studyPlan.setShutNumShouldPassAll(0);
                studyPlan.setNewNumAll(0);
            }
        }

        return iPage;
    }


    @Override
    public Page<PassRadeDetail> getTeacherRateDetail(Integer pageNum, Integer pageSize, String yearPart, String yearClassId, String classTypeId, String quarterNum, String gradeSection, Integer taskCourseNum, Integer taskCourseNumNow, String taskDateStart, String taskDateEnd, String tactType, String listState, String detailType, String teacherId, String teamId, String classify, String trackType, Integer type) {
        Quarter quarter = iQuarterService.getNowQuarter();
        if (StringUtils.isNotBlank(yearPart) && StringUtils.isNotBlank(quarterNum)) {
            quarter.setYearPart(Integer.parseInt(yearPart));
            quarter.setNum(Integer.parseInt(quarterNum));
        }

        PlanShutNum planShutNum = new PlanShutNum();

        planShutNum.setClassTypeId(classTypeId); //班型
        planShutNum.setQuarterNum(quarter.getNum()); // 学期
        planShutNum.setYearPart(quarter.getYearPart()); //年份
        planShutNum.setTaskCourseNum(taskCourseNum);//开始课次
        planShutNum.setTaskCourseNumNow(taskCourseNumNow);//结束课次
        planShutNum.setTaskDateStart(taskDateStart);//开始时间
        planShutNum.setTaskDateEnd(taskDateEnd);//结束时间
        planShutNum.setTactType(tactType);
        planShutNum.setYearClassId(yearClassId);
        planShutNum.setListState(listState);
        planShutNum.setDetailType(detailType);
        planShutNum.setTeacherId(teacherId);
        planShutNum.setPageNum(pageNum);
        planShutNum.setPageSize(pageSize);
        planShutNum.setTeamId(teamId);
        planShutNum.setClassify(classify);
        planShutNum.setTrackType(trackType);
        planShutNum.setType(type);

        Page<PassRadeDetail> hashMapList = iPlanFeignClient.getTeacherRateDetail(planShutNum);

        return hashMapList;
    }


    @Override
    public List<PassRade> getTeacherRate(String yearPart, String yearClassId, String classTypeId, String quarterNum, String gradeSection, Integer taskCourseNum, Integer taskCourseNumNow, String taskDateStart, String taskDateEnd, String tactType, String listState, String shutnumType, String teamId, String classify, String trackType, Integer type) {
        Quarter quarter = iQuarterService.getNowQuarter();
        if (StringUtils.isNotBlank(yearPart) && StringUtils.isNotBlank(quarterNum)) {
            quarter.setYearPart(Integer.parseInt(yearPart));
            quarter.setNum(Integer.parseInt(quarterNum));
        }

        PlanShutNum planShutNum = new PlanShutNum();

        planShutNum.setClassTypeId(classTypeId); //班型
        planShutNum.setQuarterNum(quarter.getNum()); // 学期
        planShutNum.setYearPart(quarter.getYearPart()); //年份
        planShutNum.setTaskCourseNum(taskCourseNum);//开始课次
        planShutNum.setTaskCourseNumNow(taskCourseNumNow);//结束课次
        planShutNum.setTaskDateStart(taskDateStart);//开始时间
        planShutNum.setTaskDateEnd(taskDateEnd);//结束时间
        planShutNum.setTactType(tactType);
        planShutNum.setYearClassId(yearClassId);
        planShutNum.setListState(listState);
        planShutNum.setShutnumType(shutnumType);
        planShutNum.setTeamId(teamId);
        planShutNum.setClassify(classify);
        planShutNum.setTrackType(trackType);
        planShutNum.setType(type);

        List<PassRade> hashMapList = iPlanFeignClient.getTeacherRate(planShutNum);

        return hashMapList;
    }

    @Override
    public List<PassRade> getMinimumTaskProgressRateNew(Integer readingStatus, String schoolId, String yearPart, String yearClassId, Integer type, String classTypeId, String quarterNum, String gradeSection, Integer taskCourseNum, Integer taskCourseNumNow, String courseTypeId, String taskDateStart, String taskDateEnd, Integer tabsType, String include, String teamId, String classify, String trackType, String categoryId, String teacherId, String tactType, String listState, String teacherName, String shutnumType, String studentName, Integer isHoliday, String moldType, Integer isYearClass, AuthAdminContent authAdminContent, LeadDataRs leadDataRs) {
        Quarter quarter = iQuarterService.getNowQuarter();
        if (StringUtils.isNotBlank(yearPart) && StringUtils.isNotBlank(quarterNum)) {
            quarter.setYearPart(Integer.parseInt(yearPart));
            quarter.setNum(Integer.parseInt(quarterNum));
        }

        PlanShutNum planShutNum = new PlanShutNum();

        planShutNum.setType(type);
        planShutNum.setSchoolId(schoolId);
        planShutNum.setReadingStatus(readingStatus);
        planShutNum.setQuarterNum(quarter.getNum());
        planShutNum.setYearPart(quarter.getYearPart());
        planShutNum.setClassTypeId(courseTypeId);
        planShutNum.setTaskCourseNum(taskCourseNum);//开始课次
        planShutNum.setTaskCourseNumNow(taskCourseNumNow);//结束课次
        planShutNum.setTaskDateStart(taskDateStart);//开始时间
        planShutNum.setTaskDateEnd(taskDateEnd);//结束时间
        planShutNum.setTabsType(tabsType);//1人数 2关数
        planShutNum.setInclude(include);//0三次课以内，1三次课以外
        planShutNum.setTeamId(teamId);
        planShutNum.setClassify(classify);
        planShutNum.setTrackType(trackType);
        planShutNum.setCategoryId(categoryId);//课程分类：1正式，2词汇量测试，3专项训练
        planShutNum.setTeacherId(teacherId);
        planShutNum.setTactType(tactType);
        planShutNum.setListState(listState);
        planShutNum.setTeacherName(teacherName);
        planShutNum.setStudentName(studentName);
        planShutNum.setShutnumType(shutnumType);
        planShutNum.setMoldType(moldType);
        planShutNum.setIsYearClass(isYearClass);
        planShutNum.setLeadDataRs(leadDataRs);
        planShutNum.setAuthAdminContent(authAdminContent);

        if (type == 3) {
            List<Long> headmasterIdList = roleAdminMapper.getAdminIdListByRoleAdmin(1568160887369994242L);
            planShutNum.setHeadmasterIdList(headmasterIdList);
        }

        planShutNum.setYearClassId(yearClassId);
        List<PassRade> hashMapList = new ArrayList<>();

        if (isHoliday == 1) {
            hashMapList = iPlanHolidayFeignClient.getMinimumTaskProgressRateEqualNew(planShutNum);
        } else {
            hashMapList = iPlanFeignClient.getMinimumTaskProgressRateEqualNew(planShutNum);
        }

        return hashMapList;
    }

    public List<PassRadeDetail> getMinimumTaskProgressRateDetailNew(Integer readingStatus, String schoolId, String teacherId, String gradeId, String yearPart, String yearClassId, Integer type, String classTypeId, String subjectsId, String quarterNum, String gradeSection, Integer pageNum, Integer pageSize, Integer taskCourseNum, Integer taskCourseNumNow, String courseTypeId, String taskDateStart, String taskDateEnd, String detailType, Integer tabsType, String include, String teamId, String classify, String trackType, String studentIdStr, String categoryId, String tactType, String studentName, String listState, String shutnumType, Integer isHoliday, String moldType, Integer isTeam, AuthAdminContent authAdminContent, LeadDataRs leadDataRs) {
        Quarter quarter = iQuarterService.getNowQuarter();
        if (StringUtils.isNotBlank(yearPart) && StringUtils.isNotBlank(quarterNum)) {
            quarter.setYearPart(Integer.parseInt(yearPart));
            quarter.setNum(Integer.parseInt(quarterNum));
        }

        PlanShutNum planShutNum = new PlanShutNum();
        planShutNum.setTeacherId(teacherId);
        planShutNum.setDetailType(detailType);
        planShutNum.setGradeId(gradeId);
        planShutNum.setSchoolId(schoolId);
        planShutNum.setQuarterNum(quarter.getNum());
        planShutNum.setYearPart(quarter.getYearPart());
        planShutNum.setClassTypeId(courseTypeId);
        planShutNum.setReadingStatus(readingStatus);
        planShutNum.setDetailType(detailType);
        planShutNum.setTaskCourseNum(taskCourseNum);//开始课次
        planShutNum.setTaskCourseNumNow(taskCourseNumNow);//结束课次
        planShutNum.setTaskDateStart(taskDateStart);//开始时间
        planShutNum.setTaskDateEnd(taskDateEnd);//结束时间
        planShutNum.setType(type);
        planShutNum.setTabsType(tabsType);//1人数，2关数
        planShutNum.setInclude(include);//0三次课以内，1三次课以外
        planShutNum.setTeamId(teamId);
        planShutNum.setClassify(classify);
        planShutNum.setTrackType(trackType);
        planShutNum.setStudentIdStr(studentIdStr);
        planShutNum.setCategoryId(categoryId);
        planShutNum.setTactType(tactType);
        planShutNum.setStudentName(studentName);
        planShutNum.setListState(listState);
        planShutNum.setShutnumType(shutnumType);
        planShutNum.setMoldType(moldType);
        planShutNum.setYearClassId(yearClassId);
        planShutNum.setIsTeam(isTeam);//0默认（原来的） 1战队
        planShutNum.setLeadDataRs(leadDataRs);
        planShutNum.setAuthAdminContent(authAdminContent);

        List<PassRadeDetail> hashMapList = new ArrayList<>();

        if (isHoliday == 1) {
            hashMapList = iPlanHolidayFeignClient.getMinimumTaskProgressRateEqualDetailNew(planShutNum);
        } else {
            hashMapList = iPlanFeignClient.getMinimumTaskProgressRateEqualDetailNew(planShutNum);
        }

        return hashMapList;
    }


    @Override
    public List<ArrivalRate> getReturnPremiumRate(Map<String, String> reMap, List<Long> baseSchoolIdList) {
        String yearPart = reMap.get("yearPart");
        String schoolId = reMap.get("schoolId");
        String yearClassId = reMap.get("yearClassId");
        String classTypeId = reMap.get("classTypeId");
        String startDate = reMap.get("startDate");
        String quarterNum = reMap.get("quarterNum");
        String endDate = reMap.get("endDate");
        String subjectsId = reMap.get("subjectsId");
        String type = reMap.get("type");
        String lessonType = "1";
        if (reMap.get("lessonType") != null) {
            lessonType = reMap.get("lessonType");
        }

        Quarter quarterNow = iQuarterService.getNowQuarter();
        //是否查看历史的，1是，0否
        Integer isHistory = 0;
        if (!String.valueOf(quarterNow.getYearPart()).equals(yearPart) || !String.valueOf(quarterNow.getNum()).equals(quarterNum)) {
            isHistory = 1;
        }

        if (StringUtils.isBlank(schoolId)) {
            if (type.equals("2")) {
                //校区老师状态，只能看自己所在校区的数据
                schoolId = baseSchoolIdList.stream().map(Object::toString).collect(Collectors.joining(","));
            }
        }

        List<ArrivalRate> suspensionRate = studentGradeMapper.getReturnPremiumRate(classTypeId, yearClassId, yearPart, quarterNum, schoolId, subjectsId, startDate, endDate, type, lessonType, isHistory);

        if (type.equals("6")) {
            List<ArrivalRate> collectList = new ArrayList<>();

            QueryWrapper queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("year_part", yearPart);
            queryWrapper.eq("quarter_num", quarterNum);
            queryWrapper.eq("pid", 0);
            List<SchoolQuarter> schoolQuarterList = iSchoolQuarterService.list(queryWrapper);

            for (SchoolQuarter schoolQuarter : schoolQuarterList) {
                ArrivalRate arrivalRate = new ArrivalRate();
                arrivalRate.setSchoolId(schoolQuarter.getSchoolId());
                arrivalRate.setSchoolName(schoolQuarter.getSchoolName());
                arrivalRate.setSchoolPid(schoolQuarter.getPid());
                arrivalRate.setStudentAllCount(0);
                arrivalRate.setReturnCount(0);

                collectList.add(arrivalRate);
            }

            for (ArrivalRate arrivalRate : collectList) {
                List<ArrivalRate> childRates = new ArrayList<>();
                for (ArrivalRate rate : suspensionRate) {
                    if (arrivalRate.getSchoolId().equals(rate.getSchoolId()) || arrivalRate.getSchoolId().equals(rate.getSchoolPid())) {
                        childRates.add(rate);
                        arrivalRate.setStudentAllCount(rate.getStudentAllCount() + arrivalRate.getStudentAllCount());
                        arrivalRate.setReturnCount(rate.getReturnCount() + arrivalRate.getReturnCount());
                    }
                }
                arrivalRate.setChildRateList(childRates);
            }

            suspensionRate = collectList;
        }

        return suspensionRate;
    }

    @Override
    public List<ArrivalRate> getReturnPremiumRateDetail(Map<String, String> reMap) {
        String yearPart = reMap.get("yearPart");
        String schoolId = reMap.get("schoolId");
        String startDate = reMap.get("startDate");
        String quarterNum = reMap.get("quarterNum");
        String yearClassId = reMap.get("yearClassId");
        String classTypeId = reMap.get("classTypeId");
        String endDate = reMap.get("endDate");
        String subjectsId = reMap.get("subjectsId");
        String type = reMap.get("type");
        String lessonType = "1";
        if (reMap.get("lessonType") != null) {
            lessonType = reMap.get("lessonType");
        }
        String teacherId = reMap.get("teacherId");
        String gradeId = reMap.get("gradeId");

        Quarter quarterNow = iQuarterService.getNowQuarter();
        Integer isHistory = 0;
        if (!String.valueOf(quarterNow.getYearPart()).equals(yearPart) || !String.valueOf(quarterNow.getNum()).equals(quarterNum)) {
            isHistory = 1;
        }
        return studentGradeMapper.getReturnPremiumRateDetail(classTypeId, yearClassId, yearPart, quarterNum, schoolId, teacherId, gradeId, subjectsId, startDate, endDate, type, lessonType, isHistory);
    }

    @Override
    public List<PassRade> keyboardPracticeList(Integer yearPart, Integer quarterNum, String taskDateStart, String taskDateEnd, String yearClassId, String gradeSection, String schoolId, String classTypeId, Integer type, String classify, String trackType, String teamId) {
        Quarter quarter = iQuarterService.getNowQuarter();
        if (yearPart != null && quarterNum != null) {
            quarter.setYearPart(yearPart);
            quarter.setNum(quarterNum);
        } else {
            quarter.setYearPart(quarter.getYearPart());
            quarter.setNum(quarter.getNum());
        }

        PlanShutNum planShutNum = new PlanShutNum();
        planShutNum.setYearPart(quarter.getYearPart());
        planShutNum.setQuarterNum(quarter.getNum());
        planShutNum.setType(type);
        planShutNum.setSchoolId(schoolId);
        planShutNum.setClassTypeId(classTypeId);
        planShutNum.setTaskDateStart(taskDateStart);
        planShutNum.setTaskDateEnd(taskDateEnd);
        planShutNum.setTeamId(teamId);
        planShutNum.setClassify(classify);
        planShutNum.setTrackType(trackType);

        if (type == 3) {
            List<Long> headmasterIdList = roleAdminMapper.getAdminIdListByRoleAdmin(1568160887369994242L);
            planShutNum.setHeadmasterIdList(headmasterIdList);
        }

        StringBuilder yearClassIdSb = new StringBuilder();
        if (gradeSection != null && !gradeSection.equals("")) {
            String[] sections = gradeSection.split(",");
            for (String section : sections) {
                if (section.equals("0")) {
                    yearClassIdSb.append("1,2");
                } else if (section.equals("1")) {
                    yearClassIdSb.append("3,4,5,6");
                } else if (section.equals("2")) {
                    yearClassIdSb.append("7,8,9");
                } else if (section.equals("3")) {
                    yearClassIdSb.append("10,11,12");
                }
                if (!section.equals(sections[sections.length - 1])) {
                    yearClassIdSb.append(",");
                }
            }
            yearClassId = yearClassIdSb.toString();
        }
        planShutNum.setYearClassId(yearClassId);

        List<PassRade> hashMapList = iPlanFeignClient.getKeyboardPracticeList(planShutNum);

        return hashMapList;
    }

    @Override
    public List<PassRadeDetail> keyboardPracticeDetails(Integer yearPart, Integer quarterNum, String taskDateStart, String taskDateEnd, String yearClassId, String gradeSection, String schoolId, String classTypeId, String teacherId, Integer type, String gradeId, String detailType, String studentIdList, String classify, String trackType, String teamId) {
        Quarter quarter = iQuarterService.getNowQuarter();
        if (yearPart != null && quarterNum != null) {
            quarter.setYearPart(yearPart);
            quarter.setNum(quarterNum);
        } else {
            quarter.setYearPart(quarter.getYearPart());
            quarter.setNum(quarter.getNum());
        }

        PlanShutNum planShutNum = new PlanShutNum();
        planShutNum.setYearPart(quarter.getYearPart());
        planShutNum.setQuarterNum(quarter.getNum());
        planShutNum.setType(type);
        planShutNum.setSchoolId(schoolId);
        planShutNum.setClassTypeId(classTypeId);
        planShutNum.setTaskDateStart(taskDateStart);
        planShutNum.setTaskDateEnd(taskDateEnd);
        planShutNum.setTeamId(teamId);
        planShutNum.setClassify(classify);
        planShutNum.setTrackType(trackType);
        planShutNum.setStudentIdStr(studentIdList);
        planShutNum.setGradeId(gradeId);
        planShutNum.setDetailType(detailType);
        planShutNum.setTeacherId(teacherId);

        StringBuilder yearClassIdSb = new StringBuilder();
        if (gradeSection != null && !gradeSection.equals("")) {
            String[] sections = gradeSection.split(",");
            for (String section : sections) {
                if (section.equals("0")) {
                    yearClassIdSb.append("1,2");
                } else if (section.equals("1")) {
                    yearClassIdSb.append("3,4,5,6");
                } else if (section.equals("2")) {
                    yearClassIdSb.append("7,8,9");
                } else if (section.equals("3")) {
                    yearClassIdSb.append("10,11,12");
                }
                if (!section.equals(sections[sections.length - 1])) {
                    yearClassIdSb.append(",");
                }
            }
            yearClassId = yearClassIdSb.toString();
        }
        planShutNum.setYearClassId(yearClassId);

        List<PassRadeDetail> hashMapList = iPlanFeignClient.getKeyboardPracticeDetails(planShutNum);

        return hashMapList;
    }

}
